﻿<%@ Page Culture="auto" UICulture="auto" Title="MForm validation" Language="C#" MasterPageFile="~/Site.Master"
    AutoEventWireup="true" CodeBehind="Validation.aspx.cs" Inherits="BM.Tools.WebControls.MForm.Example.Core.Validation" %>

<%@ Register TagPrefix="mftitle" Namespace="BM.Tools.WebControls.MForm.Controls.Titles"
    Assembly="BM.Tools.WebControls.MForm" %>
<asp:Content ID="Content1" ContentPlaceHolderID="Description" runat="server">
    <div class="Section">
        <mftitle:TitleControl runat="server" Text="Validating the Root control" />
        <p>
            The MForm controls use the ASP.NET validation scheme.
        </p>
        <p>
            There is a separate validator control for the <code>Root</code> control, it is called
            the <code>RootValidator</code>. This validator inherits from the ASP.NET <code>BaseValidator</code>
            class.
        </p>
        <p>
            All the properties available to standard .NET validators are also available in the
            <code>RootValidator</code>. These are:
        </p>
        <ul>
            <li><code>ControlToValidate</code> - the ID of the Root control, that the validator
                is attached to.</li>
            <li><code>ValidationGroup</code> - a named group of common validators</li>
            <li><code>Text</code> - a static text displayed on error</li>
            <li><code>Display</code> - a display type: None, Static or Dynamic</li>
        </ul>
        <p>
            If the error should be displayed somewhere else, the .NET <code>ValidationSummary</code>
            control may be used.
        </p>
        <div class="Remark">
            <p>
                The <code>RootValidator</code> must be placed inside the same naming container as
                the <code>Root</code> control. It is illegal to add the <code>RootValidator</code>
                inside the contents of the Root control.</p>
        </div>
    </div>
    <div class="Section">
        <mftitle:TitleControl runat="server" Text="The MForm inner validation process" />
        <p>
            The <code>RootValidator</code> control coordinates the validation of the controls
            tree inside the <code>Root</code> control, both on the client and on the server
            side.
        </p>
        <p>
            Each of the MForm item controls may contain a <code>Constraint</code> object inside
            the <code>Additions</code> property. The <code>Constraint</code> property must implement
            the <code>IsValid</code> method, that takes the item as the parameter - this way
            the validation is perforemed on server side. Each class inheriting form the <code>Constraint</code>
            also adds a client script resource to the page. When the MForm item is loaded on
            the client side, it has all the constraints registered - and they are checked on
            item values change - this way the validation is performed on the client side.
        </p>
        <div class="Remark">
            <p>
                The validation on the server side traverses recursively all the child controls that
                implement the <code>IXmlValidatingEditor</code> interface. If you want to extend
                the MForm tree with custom controls that take part in the validation process, implement
                the <code>IXmlValidatingEditor</code> interface in your control.</p>
        </div>
        <p>
            For existing MForm item constraints look in the Constraints chapter.
        </p>
    </div>
    <div class="Section">
        <mftitle:TitleControl runat="server" Text="Data type validation" />
        <p>
            In order to reduce verbosity of the MForm controls tree, one constraint does not need to be added to every leaf definition.
        </p>
        <p>
            This constraint is called the <code>DataTypeConstraint</code> and it checks if the data inside the leaf item matches the data type of the item.
        </p>
        <p>
            The data type constraint, like some of the built-in constraint, has some predefined error messages defined. These error messages are in the MForm resource files.
            To change the default error message, the data type constraint needs to be added explicitly to the item additions, and needs to have the <code>ErrorText</code> property set.
        </p>
    </div>
    <div class="Section">
        <mftitle:TitleControl runat="server" Text="The error messages" />
        <p>
            Every constraint has an <code>ErrorText</code> property. This property is a description
            of the error in case of a situation when the constraint is not met.
        </p>
        <p>
            When MForm is validated, it stops for the first constraint that is not matched.
            The displayed error text concerns the item that is the owner of the constraint.
        </p>
        <p>
            By default, the error message will only be shown on button pressing and will display
            only the data about the errorneous field.
        </p>
        <p>
            For a solution to add error messages near the fields, check the
            <asp:HyperLink NavigateUrl="~/Operations/ErrorLabelExamplePage.aspx" ID="HyperLink1"
                runat="server">Error label example page</asp:HyperLink>
        </p>
    </div>
</asp:Content>
